<%@include file="loginCheck.jsp"%>
<%@ page import="com.dao.Flight" %>
<%@ page import="com.dao.VacancyDaoImpl" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%--
  Created by IntelliJ IDEA.
  User: Phillip
  Date: 2014/5/2
  Time: 23:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<%
    Flight flight1 = new Flight();
    Flight flight2 = new Flight();
    List<String> citylist = new ArrayList<String>();

    if (session.getAttribute("citylist") != null)
        citylist = (List<String>) session.getAttribute("citylist");
    List<Flight> flightlist = (List<Flight>) request.getAttribute("flightlist");
    if (flightlist != null && flightlist.size() > 1) {
        flight1 = flightlist.get(0);
        flight2 = flightlist.get(1);
    }

    VacancyDaoImpl vacancyDao = new VacancyDaoImpl();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title></title>
</head>
<body>
<H1 align="center">
    Flight Booking Centre
</H1>

<br>
<%
    out.println("<p align=\"center\">Hi~ " + session.getAttribute("username") + "<a href=\"index.jsp?logout=1\">&nbspLOG OUT</a></p>");
%>
<br>
<form method="POST" action="/Servlet">
    <TABLE align="center">
        <TR>
            <TD>Select departing city</TD>
            <TD>
                <select name = "deptcity">
                    <%
                        for (String city : citylist) {
                        out.println("<option value=\"" + city + "\">" + city + "</option>");
                        }
                    %>
                </select>
            </TD>
            <TD>Select destination city</TD>
            <TD>
                <select name = "destcity">
                    <%
                        for (String city : citylist) {
                            out.println("<option value=\"" + city + "\">" + city + "</option>");
                        }
                    %>
                </select>
            </TD>
        </TR>
        <TR>
            <TD>Select departing date</TD>
            <TD>
                2014-03-<select name = "deptdate">
                <%
                    for (int i = 1; i < 32; i++) {
                        out.println("<option value=\"" + i + "\">" + i + "</option>");
                    }
                %>
                </select>
            </TD>
            <TD>Select return date</TD>
            <TD>
                2014-03-<select name = "returndate">
                <%
                    for (int i = 1; i < 32; i++) {
                        out.println("<option value=\"" + i + "\">" + i + "</option>");
                    }
                %>
            </select>
            </TD>
        </TR>
    </TABLE>
    <div style="text-align:center">
        <input type="submit" value="QUERY">
    </div>

</form>
<form method="post" action="book.jsp">
<TABLE BORDER="1" align="center">
    <TR>
        <TD>
            Airline/Flight/Plane
        </TD>
        <TD>
            Departing/Arriving Time
        </TD>
        <TD>
            Departing/Arriving Airport
        </TD>
        <TD>
            Rates
        </TD>
        <TD>
            Operation
        </TD>
    </TR>
    <TR>
        <TD>
            <div>
                <%
                    if (flight1.getFligthNOString() != null)
                        out.println(flight1.getAirlineString() + "/" + flight1.getFligthNOString() + "/" + flight1.getPlaneString());
                %>
            </div>
            <div>
                <%
                    if (flight1.getFligthNOString() != null)
                        out.println(flight2.getAirlineString() + "/" + flight2.getFligthNOString() + "/" + flight2.getPlaneString());
                %>
            </div>
        </TD>
        <TD>
            <div>
                <%
                    if (flight1.getFligthNOString() != null)
                        out.println(flight1.getDeptTime() + "/" + flight1.getArriTime());
                %>
            </div>
            <div>
                <%
                    if (flight1.getFligthNOString() != null)
                        out.println(flight2.getDeptTime() + "/" + flight2.getArriTime());
                %>
            </div>
        </TD>
        <TD>
            <div>
                <%
                    if (flight1.getFligthNOString() != null)
                        out.println(flight1.getDeptAirportString() + "/" + flight1.getArriAirportString());
                %>
            </div>
            <div>
                <%
                    if (flight1.getFligthNOString() != null)
                        out.println(flight2.getDeptAirportString() + "/" + flight2.getArriAirportString());
                %>
            </div>
        </TD>
        <TD>
            <%
                if (flight1.getFligthNOString() != null)
                    out.println(Integer.parseInt(flight1.getPriceString()) + Integer.parseInt(flight2.getPriceString()));
            %>
        </TD>
        <TD>
            <%
                if (flight1.getFligthNOString() != null) {
                    out.println("<input type=\"submit\" value=\"BOOK\">");
                } else {
                    out.println("<input type=\"submit\" value=\"BOOK\" disabled=\"disabled\">");
                }

            %>
            <input type="hidden" name="flightnumber1" value="<%= flight1.getFligthNOString()%>">
            <input type="hidden" name="flightnumber2" value="<%= flight2.getFligthNOString()%>">
            <input type="hidden" name="date1" value="<%= "2014-03-" + (String) request.getParameter("deptdate")%>">
            <input type="hidden" name="date2" value="<%= "2014-03-" + (String) request.getParameter("returndate")%>">
        </TD>
    </TR>
</TABLE>
</form>
</body>
</html>
